<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
<#include "/WEB-INF/views/template/bootMainCss.ftl" parse=true encoding="utf-8">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <style>
        .row{ margin: 0;}
        .search{ float: right;}
        .shop-img{ text-align: left; padding-left: 30px;}
        .shop-img img{ float: left; margin-right: 10px;}
        .shop-img span{ display: block;}
        .name{ text-align: left; padding-left: 30px;}
        .name span{ display: block;}
        #tbodyId{ font-size: 13px;}
        #myTable thead{ font-size: 14px;}
    </style>
</head>
<body>

<div class="panel panel-lzy">
    <div class="panel-body">
        <h5 class="tips-lzy">操作提示</h5>
        <ul class="tips-list-lzy">
            <li>◆&nbsp;<span>所有订单的列表，可点击查看进入订单详情页对订单进行相关操作。</span></li>
            <li>◆&nbsp;<span>请后台运营人员根据订单实际情况谨慎操作。</span></li>
        </ul>
    </div>
</div>

<div class="panel panel-f5">
    <div class="panel-body row">
        <form id="myForm" class="form-inline form-margin-right">
            <button type="button" class="btn btn-primary" onclick="exportOrderList();">导出订单</button>
            <div class="form-group search">
                <span>搜索：</span>
                <input type="text" class="form-control" id="key" size="30" placeholder="订单号/销售员名称">
                <button type="button" class="btn btn-primary btn-sm" onclick="search(1)">查询</button>
            </div>
        </form>
    </div>

    <!-- 分页查询的地址-->
    <div class="panel-body panel-white">
        <div class="table-responsive">
            <table id="myTable"
                   class="table table-hover"
                   data-url="${basePath}/admin/order/product/orderList/${status}"
                   data-pageSize="10,50,100" data-method="GET">
                <thead>
                <!-- 需要循环的字段  对应mapper文件-->
                <tr>
                    <th  data-field="banner" data-call="true">产品信息</th>
                    <th  data-field="name" data-call="true" width="15%">客户姓名</th>
                    <th  data-field="createTime" width="25%">下单时间</th>
                    <th  data-field="userName" data-call="true" width="15%">销售员</th>
                    <th  data-field="status" data-call="true" width ="10%">订单状态</th>
                    <th  data-field="button" data-call="true">操作</th>
                </tr>
                </thead>
                <tbody id="tbodyId">
                </tbody>
            </table>
        </div>
        <!-- 分页条-->
        <div class="row">
            <div align="left" class="col-xs-6">
                <div class="input-group">
                    <span class="input-group-addon" id="pageCount"></span> <select
                        id="pageSize" onchange="search(1)" class="form-control"
                        style="width: 100px"></select>
                </div>
            </div>
            <div align="right" class="col-xs-6">
                <ul class="pagination" id="pagination"></ul>
            </div>
        </div>
    </div>

</div>
<#include "/WEB-INF/views/template/bootMainJs.ftl" parse=true encoding="utf-8">
<script type="text/javascript" src="${basePath}/bootstrap/js/utils.js" type="text/javascript"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/jqPaginator/myPage.js"></script>
<script type="text/javascript">
    //循环列表数据以及操作按钮
    function tableCallBack(data, id){
        if(id == 'button') {//增加操作按钮
            var count = 0;
            var _button = '<button type="button" class="btn btn-white btn-xs" name="' + data.orderId + '" onclick="viewOrder(this);">查看 </button> ';
            count ++
            if(data.minStatus==0){
                _button += '<button type="button" class="btn btn-white btn-xs" onclick="closeSale('
                        + data.orderId +');">关闭</button> ';
                count++;
            }
            return _button;
        }
        else if(id == "status"){
            if(data[id] == "1"){
                return "<span class='text-green'>待支付</span>"
            }
            else if(data[id] == "2"){
                return "<span class='text-blue'>已完结</span>"
            }
            else if(data[id] == "3"){
                return "<span class='text-blue'>已关闭</span>"
            }
            else{
                return "<span class='text-red'>"+ data[id] +"</span>"
            }
        }
        else if(id == "name"){
            return "<div class='name'><span>"+data.name+"</span>"+data.createTime+"</div>";
        }
        else if(id == "salesmen"){
            return data.memberName ;
        }
        else if(id == "banner"){
            return "<div class='shop-img'><img src='"+data.productImage+"' height='50'><span>订单号："+data.orderId+"</span><span>"+data.productName+"</span></div>";
        }
        else {
            if(data[id] == null || data[id] == ''){
                return '';
            }else{
                return data[id];
            }
        }
    }

    //详情
    function viewOrder(obj){
        var id = obj.name;
        window.location.href='${basePath}/admin/order/product/orderDetail/'+id;
    }
    //关闭订单
    function closeSale(orderId) {
        layer.confirm('是否确定此操作？', {
            btn: ['确定','取消'] //按钮
        }, function() {
            $.ajax({
                type: 'GET',
                url: '${basePath}/admin/order/close?orderId='+orderId,
                dataType: 'json',
                data: {
                },
                success: function (data) {
                    if (data.resultVO.code == '0000') {
                        layer.alert('关闭成功!', {
                            icon: 6
                        }, function(index){
                            layer.closeAll('dialog');
                            location.reload();
                        });
                    }
                }
            });
        });
    }

    //导出
    function exportOrderList(){
        layer.confirm('是否确定此操作？', {
            btn: ['确定','取消'] //按钮
        }, function() {
            var key = $("#key").val();
            window.location.href='${basePath}/admin/order/product/exportOrderList?key='+key;
            layer.closeAll();
        });
    }

</script>
</body>
</html>